Thread: Please Help [Error] stray backslash in program

  1. #1
    Registered User
    Join Date
    Sep 2017
    Posts
    1

    Please Help [Error] stray backslash in program

    This is a CRC-CCITT example
    Compiler show a error about "" in Line 81
    But i don't used "" there
    I don't know what's wrong

    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #define CRC_INIT (unsigned short)~0
    #define CRC_CCITT 0x1021
    #define FALSE 0
    #define TRUE (!FALSE)
    
    
    #define CRCUpdate(usAccumulator, usData) \ ((usAccumulator << 8) ^ vusCRCTable[(usAccumulator >> 8) ^ usData])
    
    
    unsigned short * vusCRCTable;
    unsigned short BuildCRCTableEntry (unsigned short usData,
                                       unsigned short usPolynomial,
                                       unsigned short usAccumulator )
    {
        register int i;
        usData <<= 8;
        for( i = 8; i > 0; i-- )
            {
                if( ((usData ^ usAccumulator) & 0x8000) != 0 ) 
                {
                    usAccumulator = (usAccumulator << 1) ^ usPolynomial;
                } 
                else 
                {
                    usAccumulator <<= 1;
                }
                usData <<= 1;
            }
            return usAccumulator;
    }
        void CRCInitCRC( void )
    {
         unsigned short usPolynomial;
         int i;
    
    
         usPolynomial = CRC_CCITT;
         vusCRCTable = (unsigned short *) malloc(256 *sizeof(unsigned short));
    
    
         for( i = 0; i < 256; i++ )
             vusCRCTable[i] = BuildCRCTableEntry (i, usPolynomial, 0);
    }
    
    
    int main (int argc, const char *argv[])
    {
     const char *szFile;
     FILE *hfile;
     unsigned short cChar;
     unsigned short int usAccumulator;
     int bLinePrint;
    
    
    
    
     if (argc < 2) 
     {
         printf ("Usage: crc <input file> [-L]\n");
         exit (1);
     }
     szFile = argv[1];
    
    
     bLinePrint = FALSE;
     if (argc == 3)
     if (tolower (argv[2][1]) == 'l')
     bLinePrint = TRUE;
    
    
     CRCInitCRC();
    
    
     hfile = fopen (szFile, "rb");
     if (!hfile) 
    {
         printf ("Could not open file\n");
         exit (1);
     }
    
    
    
    
     usAccumulator = CRC_INIT;
    
    
    
    
     while ( (cChar = (unsigned short) fgetc (hfile)) != 65535) 
     {
    usAccumulator = CRCUpdate(usAccumulator, cChar);/*This line*/
    
    
    
    
     if (bLinePrint) 
         {
         putchar (cChar);
             if (cChar == '\n') 
            {
                 printf ("CRC: %04X\n", usAccumulator);
                 getch();
             }
         }
     }
    
    
     fclose (hfile);
     printf ("File CRC = %04X.\n", usAccumulator);
    
    
     exit (0);
    }
    Attached Files Attached Files

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Line 81 is actually this line:
    Code:
    usAccumulator = CRCUpdate(usAccumulator, cChar);
    There's obviously no backslash involved, but CRCUpdate is a macro, so we should look at what it expands to:
    Code:
    #define CRCUpdate(usAccumulator, usData) \ ((usAccumulator << 8) ^ vusCRCTable[(usAccumulator >> 8) ^ usData])
    Now we can see the stray backslash: there shouldn't be a backslash between the macro identifier/parameters and the replacement, unless you're introducing a physical source line, e.g.,
    Code:
    #define CRCUpdate(usAccumulator, usData) \
        ((usAccumulator << 8) ^ vusCRCTable[(usAccumulator >> 8) ^ usData])
    Therefore, you should have written:
    Code:
    #define CRCUpdate(usAccumulator, usData) ((usAccumulator << 8) ^ vusCRCTable[(usAccumulator >> 8) ^ usData])
    Actually, because usAccumulator and usData might be expressions more complex than simple variable names, it would be best to write:
    Code:
    #define CRCUpdate(usAccumulator, usData) (((usAccumulator) << 8) ^ vusCRCTable[((usAccumulator) >> 8) ^ (usData)])
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-29-2017, 02:11 AM
  2. Stray backslash
    By MoCityMM in forum C Programming
    Replies: 1
    Last Post: 04-17-2017, 11:37 AM
  3. error stray 240 in program
    By sean146 in forum C Programming
    Replies: 3
    Last Post: 11-19-2016, 07:14 PM
  4. What does: 'error: stray ‘o357’ in program' mean?
    By Phanixis in forum Linux Programming
    Replies: 8
    Last Post: 12-04-2010, 01:48 AM
  5. C compiling / error: stray ‘\’ in program
    By Elya in forum C Programming
    Replies: 5
    Last Post: 07-02-2009, 08:20 AM

Tags for this Thread